package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domin.Student;

public class StudentDao {
    private static Student[] students=new Student[40];

    public Student[] findAllStudent(){
        return students;
    }

    public boolean addStudent(Student student){
        for (int i = 0; i < students.length; i++) {
            Student stu = students[i];
            if (stu==null){
                students[i]=student;
                return true;
            }
        }
        return false;
    }
//根据学号找索引
    public int getindex(String sid){
        for (int i = 0; i < students.length; i++) {
            Student student = students[i];
            if (student!=null&&student.getSid().equals(sid)){
                return i;
            }
        }
        return -1;
    }
    public void deleteStudent(String sid){
        int getindex = getindex(sid);
        students[getindex]=null;
    }
    public void updateStudent(String sid, Student student){
        int getindex = getindex(sid);
        students[getindex]=student;
    }
}
